<?php

namespace App\Traits;

use App\Services\Api\Api;

trait NeedleTrait
{
    public function addNeedleInfo($apiCode, $data)
    {
        if ($data['needle_type'] == 1) {
            list($p, $c) = explode(',', $data['area_id']);
            $formData = [
                'custId' => $data['company_id'],
                'contact' => $data['contact_user_name'],
                'telephone' => $data['contact_user_phone'],
                'other' => $data['content'],
                'type' => $data['needle_type'], //需求类别
                'domain' => ',' . $data['domain_id'] . ',',
                'addr' => [
                    'p' => $p,
                    'c' => $c,
                    'a' => -1,
                    'd' => '',
                ],

            ];
        } else if ($data['needle_type'] == 2) {
            list($p, $c) = explode(',', $data['area_id']);
            $formData = [
                'custId' => $data['company_id'],
                'contact' => $data['contact_user_name'],
                'telephone' => $data['contact_user_phone'],
                'other' => $data['content'],
                'type' => $data['needle_type'], //需求类别
                'domain' => ',' . $data['domain_id'] . ',',
                'addr' => [
                    'p' => $p,
                    'c' => $c,
                    'a' => -1,
                    'd' => '',
                ],
            ];
        } else if ($data['needle_type'] == 3) {
            list($p, $c) = explode(',', $data['area_id']);
            $formData = [
                'custId' => $data['company_id'],
                'contact' => $data['contact_user_name'],
                'telephone' => $data['contact_user_phone'],
                'other' => $data['content'],
                'type' => $data['needle_type'], //需求类别
                'use_of_funds' => ',' . $data['money_used_id'] . ',',
                'expected_amount' => $data['money_sum_id'],
                'nature' => $data['project_type_id'],
                'addr' => [
                    'p' => $p,
                    'c' => $c,
                    'a' => -1,
                    'd' => '',
                ],
            ];
        } else if ($data['needle_type'] == 4) {
            $formData = [
                'custId' => $data['company_id'],
                'contact' => $data['contact_user_name'],
                'telephone' => $data['contact_user_phone'],
                'other' => $data['content'],
                'domain' => ',' . $data['domain_id'] . ',',
                'techordev_type' => $data['tech_id'],
            ];
        } else if ($data['needle_type'] == 0) {
            $formData = [
                'custId' => $data['company_id'],
                'contact' => $data['contact_user_name'],
                'telephone' => $data['contact_user_phone'],
                'other' => $data['content'],
            ];
        }

        $obj = new Api();
        $postData = $obj->getJavaPostData($apiCode, $formData);
        $result = $obj->getJavaResponseData($postData);
        if ($result && $result['succ'] == 1) {
            return true;
        }
        return false;
    }
}
